package com.abc.robot01.activity.compose

import android.os.Bundle
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.LinearLayout
import android.widget.ScrollView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.GenericShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.zIndex
import com.abc.robot01.R
import com.abc.robot01.activity.DrawScrollableView
import com.abc.robot01.activity.px

class BoxDemo : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Text(text = "Hello ".repeat(20),
                fontSize = (24 / 3.5f).sp,
                color = Color.Black,
                modifier = Modifier. width(140.px),
                overflow = TextOverflow.Ellipsis,
                maxLines = 1
            )
//            MY()

//            val scrollState = rememberScrollState()
//                Column(
//                    verticalArrangement = Arrangement.spacedBy(16.dp),
//                    modifier = Modifier
//                        .verticalScroll(scrollState)
//                        .fillMaxSize()
//                ) {
//                    MaterialTheme {
//                        Box02()
//                    }
//                    Box02()
////                ZIndexBox()
//
////                ClippedBox()
////                CustomClip()
////                Box01()
//            }
        }
    }
}

//@Composable
//fun Box02() {
//    val rippleIndication = rememberRipple(bounded = true, color = Color.Blue)
//    CompositionLocalProvider(LocalIndication provides rippleIndication) {
//        Box(
//            modifier = Modifier
//                .width(100.dp)
//                .clickable { }
//                .height(100.dp)
//        )
//        {
//
//        }
//    }
//}


@Composable
fun Box01() {
    Box {
        Box(
            Modifier
                .fillMaxSize()
                .background(Color.Cyan)
        )
        Box(
            Modifier
                .matchParentSize()
                .padding(top = 20.dp, bottom = 20.dp)
                .background(Color.Yellow)
        )
        Box(
            Modifier
                .matchParentSize()
                .padding(40.dp)
                .background(Color.Magenta)
        )
        Box(
            Modifier
                .align(Alignment.Center)
                .size(300.dp, 300.dp)
                .background(Color.Green)
        )
        Box(
            Modifier
                .align(Alignment.TopStart)
                .size(150.dp, 150.dp)
                .background(Color.Red)
        )
        Box(
            Modifier
                .align(Alignment.BottomEnd)
                .size(150.dp, 150.dp)
                .background(Color.Blue)
        )
    }
}

    @Composable
    fun ZIndexBox() {
        Box(
            modifier = Modifier.size(120.dp)
        ) {
            Box(
                modifier = Modifier
                    .size(100.dp)
                    .background(Color.Red)
                    .zIndex(10f) // 置于上层
            )
            Box(
                modifier = Modifier
                    .size(100.dp)
                    .background(Color.Blue)
                    .align(Alignment.BottomEnd)
                    .zIndex(1f) // 置于下层
            )
        }
    }




@Composable
fun  MY(){
    DrawScrollableView(
        modifier = Modifier
            .fillMaxWidth()
            .fillMaxHeight(),
        content = {
            Column {
                repeat(20) {
                    Row {
                        Text(text = "Jetpack scroll view")
                        Spacer(modifier = Modifier.size(20.dp))
                        Image(painter = painterResource(id = R.drawable.a2), contentDescription = null)
                    }
                }
            }
        }
    )

}








